<?php


namespace app\controller;


use support\Request;

class BaseController
{
    public function success($data,$message = "",$code = 200)
    {
        return response(json_encode([
            "data"=>$data,
            "message"=>$message,
            "code"=>$code
        ]));
    }

    public function error($message, $code=400)
    {
        return response(json_encode([
            "data"=>[],
            "message"=>$message,
            "code"=>$code
        ]));
    }

    public function ok($message, $code=200)
    {
        return response(json_encode([
            "data"=>[],
            "message"=>$message,
            "code"=>$code
        ]));
    }

    public function res($data)
    {
        if ($data['status']){
            return $this->success($data['data'],$data['msg'],$data["code"]);
        }
        return $this->error($data['msg'],$data["code"]);
    }

    public function getPageInfo():array
    {
        $data['page_size'] = \request()->input("page_size", 15);
        $data['page_no'] = \request()->input("page_no",1);
        return $data;
    }

}